
#!/usr/bin/python3
# -*- coding: utf-8 -*-
'''
# @file   : whicy_day.py
# @author : weichy
# @date   : 2019/01/03
# @version: 4.0
# @desc   : 输入某年某月某日，判断这是这一年的第几天。
            用列表代替元祖
            将月份写入字典
'''

import datetime


def is_leap_year(year):
    '''
    判断year是否为闰年
    是，返回true
    否，返回false
    '''
    is_leap = False

    if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
        is_leap = True
    return is_leap


def main():
    """
    """
    input_date_str = input('请输入日期（yyyy/mm/dd）:')
    input_date = datetime.datetime.strptime(input_date_str, '%Y/%m/%d')

    year = input_date.year
    month = input_date.month
    day = input_date.day

    # 初始化值
    days = 0
    days += day

    # 创建包换30天月份的集合
    _30_days_month_set = {4, 6, 9, 11}
    _31_days_month_set = {1, 3, 5, 7, 8, 10, 11}

    # 月份-天数字典
    month_day_dict = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31,
                      6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}

    for i in range(1, month):
        days += month_day_dict[i]

    # 计算之前每月的天数以及当前月的天数
    # days_in_month_tup = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
    # days_in_month_list = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    if is_leap_year(year) and month > 2:
        days += 1
    # days = sum(days_in_month_list[: month-1]) + day
    # if month > 2 and (year % 400 == 0) or ((year % 400 == 0) and (year % 100 != 0)):
    # if month > 2 and is_leap_year(year):
    #     days += 1
    print('这是第{}天'.format(days))


if __name__ == '__main__':
    main()
